<?php
require_once("../../../util/configuration/configuration_parametters.php");
require_once("../../../util/" . MESSAGES_PROPERTIES . "messages_model.php");
require_once("../../../util/exception/exception_handler.php");

require_once("../../autor/to/autor_to.php");
require_once("../../autor/dao/autor_dao_factory.php");

class Autor_dao_test {

	private $dao;
	
	public function __construct() {}	
	
	public function before_test() {
		
		$this->dao = Autor_dao_factory::singleton()->get_dao(); 
	}
	
	public function run_test() {		
		try {			
			$autor = new Autor_to('xxxxxxxxxxxx','password','email');			
			echo 'autor: ';
			echo $autor->to_string();
			echo '<br/>';
			
			$this->dao->create($autor);
			echo 'create<br/>';
			
			if ($this->dao->exist($autor->get_login())) {
				
				$result = $this->dao->find_by_login_autor($autor->get_login());
				echo 'find<br/>';
								
				$aux_autor = new Autor_to($result['login'], $result['password'], $result['email']);
				
				if ($autor->equals($aux_autor)) {
					$autor->set_password('password2');
					$this->dao->update($autor);
					echo 'update<br/>';
					
					$result = $this->dao->find_by_login_autor($autor->get_login());
					$aux_autor = new Autor_to($result['login'], $result['password'], $result['email']);
					echo 'autor: ';
					echo $aux_autor->to_string();
					echo '<br/>';		
				}
				
				$this->dao->remove($autor->get_login());
				echo 'remove<br/>';
				
			}		
		}
		catch (exception $e) {
			Exception_handler::singleton()->handler($e);
		}
	}
	
	public function after_test() {}
}

//test
$test = new Autor_dao_test();

$test->before_test();
$test->run_test();
$test->after_test();


?>